package com.pmcc.utils;

import com.pmcc.core.config.utils.PageRequest;
import org.springframework.data.domain.Sort;

/**
 * 分页工具类
 * Created by Admin on 2016/1/25.
 */
public class AntdPage {

    public static final String ASC = "ASC";

    public static final String DESC = "DESC";

    private int defaultCurrent = 1; // 当前页码

    private int startNum;//分页查询起始

    private int pageSize = 10; // 每页数量

    private String sort;// 排序字段

    private String order;// ASC、DESC

    private PageRequest pageRequest;// jpa分页参数


    public PageRequest getPageRequest() {



        if (sort != null && !"".equals(sort)) {
            Sort s = null;
            if ("DESC".equals(order)) {
                s = new Sort(Sort.Direction.DESC, sort);
            } else {
                s = new Sort(Sort.Direction.ASC, sort);
            }
            return new PageRequest(defaultCurrent, pageSize, s);
        }
        return new PageRequest(defaultCurrent, pageSize);
    }

    public int getStartNum(){
        return (this.defaultCurrent-1)*this.pageSize;
    }
    public void setPageRequest(PageRequest pageRequest) {
        this.pageRequest = pageRequest;
    }

    public int getDefaultCurrent() {
        return defaultCurrent;
    }

    public void setDefaultCurrent(int defaultCurrent) {
        this.defaultCurrent = defaultCurrent;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }
}
